﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Openfree.Workflow.Common;

public partial class SiteAdmin_WorkflowAdd : SiteAdminBase
{
    private Control control;
    private DataSet dsImage;


    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            InitData();

            string doAction = Request["Do"];
            if (!string.IsNullOrEmpty(doAction))
            {
                if ("Save".Equals(doAction))
                {
                    TipMessage1.ShowMessage("保存成功，请继续开始新的流程", 5000);
                }

                if ("Submit".Equals(doAction))
                {
                    TipMessage1.ShowMessage("申请成功，请继续开始新的流程", 5000);
                }
            }
        }
    }

    public void InitData()
    {
        string cmdText = @"select a.*,b.CodeName GroupCodeName, '查看' ImageUrl from T_WorkflowCategory a 
                left join T_CodeConfig b on a.GroupCode=b.CodeValue and 
                b.Category='WorkflowGroup' where a.IsUsed=1 order by OrderIndex";
        DataSet ds = BaseAccess.GetDataSet(base.Connection, cmdText);
        dsImage = WorkflowAccess.LoadWorkflowImage();
        gridView.DataSource = ds.Tables[0];
        gridView.DataBind();
        pnlGrid.Visible = true;
    }

    
    protected void gridView_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            DataRow[] rows = dsImage.Tables[0].Select("ForeignKey='" +((HiddenField)e.Row.Cells[0].Controls[1]).Value + "'");
            if(rows.Length>0)
            {
                ((HyperLink)e.Row.Cells[3].Controls[0]).NavigateUrl = "~/PMSWeb/Photo/Workflow/" + rows[0]["FileName"].ToString();
            }
        }
    }

    protected void btnSelect_Click(object sender, EventArgs e)
    {
        if (string.IsNullOrEmpty(Request["CategoryCode"]))
        {
            TipMessage1.ShowMessage("请选择一条记录", 5000);
            InitData();
            return;
        }
        string cmdText = @"select a.*, b.CodeName GroupCodeName from T_WorkflowCategory a 
                right join T_CodeConfig b on a.GroupCode=b.CodeValue where 
                b.Category='WorkflowGroup' and a.CategoryCode='{0}' order by OrderIndex";
        DataSet ds = BaseAccess.GetDataSet(base.Connection, string.Format(cmdText, Request["CategoryCode"]));

        Response.Redirect(ds.Tables[0].Rows[0]["ActivityPage"].ToString() +
            "?CategoryCode=" + Request["CategoryCode"] + "&Do=Edit");
    }
}
